using System;
using System.Collections.Generic;
using System.Text;

namespace LSO
{
    public static class Helpers
    {
        public static byte[] BigEndian(byte[] input)
        {
            if (BitConverter.IsLittleEndian)
            {
                int si = 0;
                int di = input.Length - 1;
                byte[] output = new byte[input.Length];
                do
                {
                    output[di] = input[si];
                    si++;
                    di--;
                } while (di >= 0);
                return output;
            }
            else
            {
                return input;
            }
        }

        public static byte[] Hex2Bytes(string text)
        {
            int index;
            string pair;
            byte[] output = new byte[text.Length / 2];
            int paircount = (int)(text.Length / 2);
            if (paircount > 0)
            {
                for (index = 0; index < paircount; index++)
                {
                    pair = text.Substring(index * 2, 2);
                    output[index] = Convert.ToByte(pair, 16);
                }
            }
            return output;
        }
    }
}
